// pages/index/page/blessing/blessing.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowWidth: 0, // 可使用窗口宽度
    windowHeight: 0, // 可使用窗口高度
    hiddenName: 'hide',
    hiddenbox: 'hide',
    fu:'',
    img_url:'',
    isIphoneX: false,
    uid:'',
    myUid:'',
    bannerList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
     
        var xxx = 'iPhone X'
        if (res.model.indexOf(xxx) > -1) {
          that.setData({
            isIphoneX: true,        
          })
        }
      }
    })
   
    if(options.uid > 0){
      that.setData({
        myUid: options.uid
      })
    }
   
    that.getBanner()
    that.getUid()
    that.getid()
  },
  getUid: function () {
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/getUid',
      data: {
        myId: app.globalData.myId
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
      
        if (res.data.status === 1) {
          that.setData({
            uid: res.data.uid
          })

          wx.hideLoading()
        } else {
        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  getBanner: function () {
    var that = this

    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/prize',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.hideLoading()
          that.setData({
            bannerList: res.data
          })
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    const vm = this
    vm.setData({
      statusBarHeight: getApp().globalData.statusBarHeight,
      titleBarHeight: getApp().globalData.titleBarHeight
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: '#000000'
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  q: function () {
    wx.navigateBack({ changed: true })
  },
  qq: function () {
    wx.switchTab({
      url: '/pages/index/index',
    });
  },
  getid :function(){
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/Index',
      data: {
        myId: app.globalData.myId,
        uid: that.data.myUid
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status === 1) {
    
          that.setData({
            fu: res.data.fu,
            img_url: res.data.img_url,
            hiddenbox: 'show'
          })

          wx.hideLoading()
        } else if (res.data.status === 2) {
     
          that.setData({
            hiddenbox: 'hide'
          })
        }else{
          
        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  showName: function () {
    this.setData({
      hiddenName: 'show'
    })
  },
  hideName: function () {
    this.setData({
      hiddenName: 'hide'
    })
  },
  hiddenbox: function () {
    this.setData({
      hiddenbox: 'hide'
    })
  },
  toBlessingBox: function () {
    if (app.globalData.myId == null || app.globalData.myId == undefined || app.globalData.myId == '') {
  
      wx.navigateTo({
        url: '../../../login/login',
      })
    } else {
      wx.navigateTo({
        url: '../blessingbox/blessingbox',
      });
    }
    
  },
  toBlessingNumber: function () {
    
    if (app.globalData.myId == null || app.globalData.myId == undefined || app.globalData.myId == '') {
    
      wx.navigateTo({
        url: '../../../login/login',
      })
    } else {
      wx.navigateTo({
        url: '../blessingNumber/blessingNumber',
      });
    }
   
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  onShareAppMessage: function (ops) {
    if (app.globalData.myId == null || app.globalData.myId == undefined || app.globalData.myId == '') {

      wx.navigateTo({
        url: '../../../login/login',
      })
    }else{

    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
     
    }
    return {
      title: '集齐五福可获得周骊晓老师墨宝一副',
      path: "pages/index/page/blessing/blessing?uid=" + this.data.uid,
      success: function (res) {
     
      },
      fail: function (res) {
     
      }
    }
  }
  }
})